﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoderJoe.Samples.IndirectImplementation.MyImplementation
{
	class Program
	{
		static void Main(string[] args)
		{
			bool success = false;

			do
			{
				Console.WriteLine("Simulate Failure? ( Y | N )");
				string result = Console.ReadLine();
				if (result.ToUpper().StartsWith("Y"))
				{
					System.IO.File.Move("CoderJoe.Samples.IndirectImplementation.MyImplementation.dll", "CoderJoe.Samples.IndirectImplementation.MyImplementation.bak");
					success = true;
				}
				else if (result.ToUpper().StartsWith("N"))
				{
					success = true;
				}
				else
				{
					Console.WriteLine("Unable to determine response, please answer Y or N");
				}
			}
			while (!success);

			IImplementation implementation = Factory.CreateImplementation();
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.WriteLine(implementation.GetMessage());

			Console.ResetColor();
			Console.WriteLine("Press any key to exit.");
			Console.ReadKey();

			if(System.IO.File.Exists("CoderJoe.Samples.IndirectImplementation.MyImplementation.bak"))
				System.IO.File.Move("CoderJoe.Samples.IndirectImplementation.MyImplementation.bak", "CoderJoe.Samples.IndirectImplementation.MyImplementation.dll");
		}
	}
}
